﻿<UserControl x:Name="userControl" 
    x:Class="HeritageAcademy.Library.Controls.ReadingView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:Controls="clr-namespace:HeritageAcademy.Library.Controls"
	xmlns:Converters="clr-namespace:HeritageAcademy.Library.Converters"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    mc:Ignorable="d" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:ViewModel="clr-namespace:HeritageAcademy.Models.ViewModels;assembly=HeritageAcademy.Models" 
    d:DesignHeight="738.747" d:DesignWidth="839.846">
	
    <UserControl.Resources>
		<Converters:BoolToVisibilityConverter x:Key="InvertedBoolToVisibilityConverter" IsInverted="True" />
		<Converters:MaxCoverter x:Key="AtLeastOneConverter" CompareValue="1" />
    </UserControl.Resources>
    
	<Grid>
        <!-- Bottom Shading -->
        <Border VerticalAlignment="Bottom" Height="25" Grid.RowSpan="10">
            <Border.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="#00000000" Offset="0" />
                    <GradientStop Color="#18000000" Offset="1" />
                </LinearGradientBrush>
            </Border.Background>
        </Border>

        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <!-- Content -->
            <ContentControl>
                <Grid x:Name="Page" Margin="18,18,18,0" MaxWidth="1000">

                    <!-- Page Background -->
                    <Border Background="{DynamicResource PageBackgroundBrush}" IsHitTestVisible="False">
                        <Border.Effect>
                            <DropShadowEffect Direction="-90" BlurRadius="12" ShadowDepth="3" Opacity="0.4" />
                        </Border.Effect>
                    </Border>

                    <!-- Position -->
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,15">
                        <ToggleButton x:Name="PositionToggle" Style="{DynamicResource InvisibleToggleButton}">
                            <Grid>
                                <TextBlock Visibility="{Binding IsChecked, Converter={StaticResource InvertedBoolToVisibilityConverter}, ElementName=PositionToggle}" x:Name="PageNumberTextBlock" Foreground="{DynamicResource PageTextBrush}" FontSize="14" VerticalAlignment="Center" ><InlineUIContainer>
                            		<TextBlock Text="{Binding CurrentPosition, Converter={StaticResource AtLeastOneConverter}, ElementName=BookViewer}" FontWeight="Bold" />
                            	</InlineUIContainer><Run Text=" "/><InlineUIContainer>
                            		<TextBlock Text="из" />
                            	</InlineUIContainer><Run Text=" "/><InlineUIContainer>
                            		<TextBlock Text="{Binding PositionCount, ElementName=BookViewer}" Margin="0,0,5,0" />
                            	</InlineUIContainer></TextBlock>
                                <TextBlock Visibility="{Binding IsChecked, Converter={StaticResource BoolToVisibilityConverter}, ElementName=PositionToggle}" x:Name="PercentTextBlock" Foreground="{DynamicResource PageTextBrush}" FontSize="14" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding Percentage, ElementName=BookViewer, StringFormat=0.0%}" />
                            </Grid>
                        </ToggleButton>
                    </StackPanel>

                    <!-- Document Viewer -->
                    <!--<c:BookViewer x:Name="BookViewer" Margin="40,40,40,50" BookLoadingProgressChanged="BookViewer_BookLoadingProgressChanged" CurrentLocation="{Binding CurrentLocation, Mode=TwoWay}" stylustouch:StylusTouchGestureEvents.Gesture="Page_Gesture" stylustouch:StylusTouchEvents.ManipulationDelta="Page_ManipulationDelta" >-->
                    <Controls:BookViewer x:Name="BookViewer" Margin="40,40,40,50" BookLoadingProgressChanged="BookViewer_BookLoadingProgressChanged" CurrentLocation="{Binding CurrentLocation, Mode=TwoWay}"/>
                    <!--<i:Interaction.Behaviors>
                            <stylustouch:FlickBehavior AllowedDirection="Horizontal" FlickLength="144" />
                            <stylustouch:TouchListenerBehavior ListenForTouch="True" ElementOrigin="{Binding ElementName=BookViewer}" MultiTouchAction="Zoom" />
                        </i:Interaction.Behaviors>
                    </c:BookViewer>-->

                    <!-- Bookmark Button -->
                    <ToggleButton x:Name="BookMarkToggleButton" Style="{DynamicResource BookmarkButton}" Margin="0,-5,-5,0" Width="60" Height="60" VerticalAlignment="Top" HorizontalAlignment="Right" Focusable="False" IsChecked="{Binding CurrentPageHasBookmark, ElementName=userControl, Mode=TwoWay}" ToolTip="Сделать закладку" />

                    <!-- Table of Contents Button -->
                    <ToggleButton HorizontalAlignment="Left" VerticalAlignment="Top" IsChecked="{Binding IsOpen, ElementName=TocFlyout, Mode=TwoWay}" ToolTip="Содержание" >
                        <ToggleButton.Style>
                            <Style BasedOn="{StaticResource TopIconToggleButton}" TargetType="{x:Type ToggleButton}">
                                <Setter Property="Width" Value="32" />
                                <Setter Property="Height" Value="32" />
                                <Setter Property="Content" Value="{StaticResource TableOfContents}" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsTouchResizeEnabled, Source={x:Static ViewModel:OptionsViewModel.Current}}" Value="True">
                                        <Setter Property="Width" Value="48" />
                                        <Setter Property="Height" Value="48" />
                                        <Setter Property="Content" Value="{StaticResource TableOfContentsTouch}" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ToggleButton.Style>
                    </ToggleButton>

                    <!-- Table of Contents Popup -->

                    <Controls:TableOfContentsView x:Name="TocFlyout" VerticalAlignment="Top" HorizontalAlignment="Left" DataContext="{Binding TableOfContents}">
                        <Controls:TableOfContentsView.Style>
                            <Style TargetType="{x:Type UserControl}">
                                <Setter  Property="Margin" Value="16,12,0,0" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsTouchResizeEnabled, Source={x:Static ViewModel:OptionsViewModel.Current}}" Value="True">
                                        <Setter  Property="Margin" Value="24,18,0,0" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Controls:TableOfContentsView.Style>
                    </Controls:TableOfContentsView>

                    <!-- Selection Menu -->

                    <Canvas  Margin="18,26,22,0" Background="{x:Null}" HorizontalAlignment="Right">
                        <ContentControl x:Name="AnnotationTools" Style="{StaticResource AnnotationOptionsContainer}" Margin="-25,13,25,-13">
                            <StackPanel Margin="0"  >
                                <Button x:Name="HighlightButton" Click="HighlightButton_Click" Style="{StaticResource OpacityButton}" Width="24" Height="24" ToolTip="Выделить текст" >
                                    <Path Width="13" Height="13" Fill="{DynamicResource StandardForegroundBrush}"  HorizontalAlignment="Center" VerticalAlignment="Center" Data="{StaticResource Highlight}" Stretch="Fill"/>
                                </Button>
                                <Button x:Name="DeleteButton" Click="DeleteButton_Click" Style="{StaticResource OpacityButton}" Width="24" Height="24"  Margin="0,0,0,3" ToolTip="Снять выделение">
                                    <Path Width="10" Height="10" Stroke="{DynamicResource StandardForegroundBrush}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="{StaticResource CloseX}" Stretch="Fill" StrokeThickness="3"/>
                                </Button>
                                <Button x:Name="CopyButton" Click="CopyButton_Click" Style="{StaticResource OpacityButton}" Width="24" Height="24"  Margin="0,0,0,0" ToolTip="Копировать выделенный текст">
                                    <Path Width="10" Height="12" Fill="{DynamicResource StandardForegroundBrush}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0.9,1.8 L2.2,1.8 2.2,2.5 C2.2,3.0 2.6,3.4 3.1,3.4 L8.8,3.4 C9.3,3.4 9.7,3.0 9.7,2.5 L9.7,1.8 11.0,1.8 C11.5,1.8 12,2.2 12,2.7 L12,13.1 C12,13.6 11.5,14 11.0,14 L0.9,14 C0.4,14 -5.9E-08,13.6 0,13.1 L0,2.7 C-5.9E-08,2.2 0.4,1.8 0.9,1.8 z M3.9,0 L8.0,0 C8.3,0 8.6,0.2 8.6,0.5 L8.6,1.6 C8.6,2.0 8.3,2.2 8.0,2.2 L3.9,2.2 C3.6,2.2 3.3,2.0 3.3,1.6 L3.3,0.5 C3.3,0.2 3.6,0 3.9,0 z" Stretch="Fill"/>
                                </Button>
                            </StackPanel>
                        </ContentControl>
                    </Canvas>


                </Grid>
            </ContentControl>

            <!-- Bottom Navigation-->           
            <Grid x:Name="BottomNavigation" Grid.Row="1" VerticalAlignment="Bottom" SnapsToDevicePixels="True" MaxWidth="1000">
                
                <Grid.Style>
                    <Style TargetType="{x:Type Grid}">
                    	<Setter Property="Height" Value="40" />
                        <!-- for TouchScreens
                        <Style.Triggers>
                        	<DataTrigger Binding="{Binding IsTouchResizeEnabled, Source={x:Static ViewModel:OptionsViewModel.Current}}" Value="True">
                        		<Setter Property="Height" Value="46" />
                        	</DataTrigger>
                        </Style.Triggers>-->
                    </Style>
                </Grid.Style>

                <Grid.ColumnDefinitions>
                	<ColumnDefinition Width="*" />
                	<ColumnDefinition Width="Auto" />
                	<ColumnDefinition Width="10000*" MaxWidth="450" MinWidth="150" />
                	<ColumnDefinition Width="Auto" />
                	<ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

            	<Controls:BookViewerSlider Grid.Column="2" Margin="10,0"  Focusable="False" BookView="{Binding ElementName=BookViewer}"/>

                <!-- Separator -->

            	<Rectangle Grid.Column="3" Width="1" Height="12" Fill="#40000000" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,0,0" />
            	<Rectangle Grid.Column="3" Width="1" Height="12" Fill="#40FFFFFF" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="1,0,0,0" />

                <!-- Options Button -->

            	<ToggleButton Visibility="Visible" x:Name="OptionsButton" Style="{StaticResource BottomIconToggleButton}" Padding="10,8,10,12" Grid.Column="3" HorizontalAlignment="Left" Content="{StaticResource ReadingOptions}" Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}" IsChecked="{Binding IsOpen, ElementName=OptionsFlyout, Mode=TwoWay}" Margin="0,2,0,-2" ToolTip="Настройки" />

                <!-- Options Dialog -->

            	<Controls:OptionsView x:Name="OptionsFlyout" Grid.Column="3" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="22,32,0,0" Visibility="Collapsed" />

                <!-- Next Page Button -->

            	<RepeatButton x:Name="NextPageButton" Grid.Column="4" Style="{StaticResource OpacityRepeatButton}" Click="NextPageButton_Click" Focusable="False" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Cursor="Hand" Padding="0,0,18,0" ToolTip="Следующая страница" >
            		<Controls:Bitmap Source="..\..\Images\arrow_next.png" />
            	</RepeatButton>

                <!-- Previous Page Button -->

            	<RepeatButton x:Name="PreviousPageButton" Grid.Column="0" Style="{StaticResource OpacityRepeatButton}" Click="PreviousPageButton_Click" Focusable="False" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Cursor="Hand" Padding="18,0,0,0" ToolTip="Предыдущая страница" >
            		<Controls:Bitmap Source="..\..\Images\arrow_prev.png" />
            	</RepeatButton>

            </Grid>
            
            <!-- Loading UI -->
            <Grid x:Name="LoadingIndicator" Width="168" Height="68" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="47, -9,0,0" Visibility="Collapsed" >
                <Border>
                    <Border.Effect>
                        <BlurEffect Radius="8" />
                    </Border.Effect>
                    <Controls:CalloutShape Fill="#A4000000"  ArrowHeight="15" ArrowWidth="17" RenderTransformOrigin="0,0">
                        <Controls:CalloutShape.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="0.93" ScaleY="0.98" />
                                <SkewTransform AngleY="2.5" />
                                <RotateTransform />
                                <TranslateTransform X="2" Y="2" />
                            </TransformGroup>
                        </Controls:CalloutShape.RenderTransform>
                    </Controls:CalloutShape>
                </Border>
                <Controls:CalloutShape Fill="{StaticResource LogoBackgroundBrush}" ArrowHeight="15" ArrowWidth="17" />
                <TextBlock FontFamily="{StaticResource PrimaryFontFamily}" Foreground="White" FontSize="15px" Text="Загрузка... " HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="14,0,0,11" />
                <TextBlock x:Name="PercentLoadedTextBlock" FontFamily="Cambria" Foreground="White" FontSize="36" Text="0%" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,8,5" />
            </Grid>
        </Grid>
    </Grid>
</UserControl>
